package tmall.framework.utils;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;
import tmall.framework.eobj.EObj;
import tmall.framework.exception.FrameworkExceptionDict;
import tmall.framework.exception.TException;

import javax.annotation.Resource;
import java.util.concurrent.TimeUnit;

@Component
public class RedisTemplateUtil<T extends EObj> {

    private static RedisTemplate<String, String> redisTemplate;

    @Autowired
    private void setRedisTemplate(RedisTemplate<String, String> redisTemplate){
        this.redisTemplate = redisTemplate;
    }

    public static boolean set(String key, String value) {
        redisTemplate.opsForValue().set(key, value);
        return true;
    }

    public static boolean set(String key, String value, long expireTime) {
        redisTemplate.opsForValue().set(key, value, expireTime, TimeUnit.MINUTES);
        return true;
    }

    public static String get(String key) {
        redisTemplate.opsForValue().get(key);
        return redisTemplate.opsForValue().get(key);

    }
    public static boolean remove(String key) {
        redisTemplate.delete(key);
        return true;
    }


}
